<template>
	<view style="background-color: #333333;height: 100%;">
		<!-- <u-navbar :title="title"></u-navbar> -->
		<u-navbar :title="$t('base.f0')"></u-navbar>
		<view id="top_div">
			<view>
				<text>{{$t('base.f1')}}</text>
			</view>
			<view>
				<view id="money_total_div">
					<text id="total_amount">{{totalAmount}}</text>
					<text style="font-size: 24rpx;">USDT</text>
					<text style="font-size: 22rpx;margin: 0 0 0 24rpx;color: #a6a6a6;" @click="onToBuyList">查看更多></text>
				</view>
			</view>
			<view id="top_btm_3_div">
				<view class="top_btm_item_div">
					<text class="color_gray">{{$t('base.f2')}}</text>
					<text>{{day_rate}}%</text>
				</view>
				<view class="top_btm_item_div">
					<text class="color_gray">{{$t('base.f3')}}</text>
					<text>{{parseFloat(total_interest)}}</text>
				</view>
				<view class="top_btm_item_div">
					<text class="color_gray">{{$t('base.f5')}}</text>
					<text>{{orderCount}}</text>
				</view>
			</view>
			<view id="btn_weituo" @click="onToBuyList">
				<text>{{$t('base.f6')}}</text>
			</view>
		</view>
		<view id="wk_list_div">
			<view class="wk_item_div" v-for="item in list">
				<view style="display: flex;justify-content: space-between;">
					<text>{{item.k_name_zh}}</text>
					<text class="btn_suocang" @click="jump(item)">{{$t('base.f8')}}</text>
				</view>
				<view class="wk_item_btm_div">
					<view class="wk_item_btm_item_div">
						<text class="color_gray">{{$t('base.f9')}}</text>
						<text>{{parseFloat(item.min_amount)}}</text>
					</view>
					<view class="wk_item_btm_item_div">
						<text class="color_gray">{{$t('base.f10')}}</text>
						<text> {{parseFloat(item.max_amount)}} </text>
					</view>
					<view class="wk_item_btm_item_div">
						<text class="color_gray">{{$t('base.f11')}}</text>
						<text style="font-size: 22rpx;">{{item.updated_at}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import config from '../../app.js'
	import Wk from "@/api/a_wk";
	export default {
		data() {
			return {
				// 参考版矿机对象
				// {
				// 	created_at: "2022-06-02 01:09:13",
				// 	currency_id: 3,
				// 	currency_logo: "https://www.hcglobal.top/upload/1603124303701058.png",
				// 	currency_name: "USDT",
				// 	day: 3,
				// 	id: 20,
				// 	interest_rate: "0.3000",
				// 	save_min: "10.00000000"
				// }
				// 正式版矿机对象
				// {
				// 	"id": 1,
				// 	"created_at": "2021-08-30 15:43:24",
				// 	"updated_at": "2021-11-25 11:25:29",
				// 	"min_amount": "0.0000",
				// 	"max_amount": "500000.0000",
				// 	"k_name_zh": "矿机1号",
				// 	"status": 1,
				// 	"sort": 3
				// }
				list: [],
				order: [],
				totalAmount: 0, // 正在托管的资金
				orderCount: 0, // 托管中的订单,
				day_rate: 0, // 日收益率
				total_interest: 0.00, // 累计收益
			}
		},

		mounted() {
			// api/user/machine  矿机列表
			// api/user/machine_details   矿机详情
			// api/user/machine_buy 购买矿机
			// console.log('baseUrl = ', config.baseUrl);

			this.getWkList()
			this.getBuyList()
		},

		methods: {
			onToBuyList() {
				uni.navigateTo({ url: '/pages/a_wk/wk_buy_list' })
			},
			jump(item) {
				// uni.setStorageSync('lockming', item)
				uni.navigateTo({ url: `/pages/a_wk/wk_zq_list?id=${item.id}` })
			},
			getWkList() {
				Wk.getMachineList({}).then(res => {
					// console.log('getMachineList.res.data = ', res.data);
					this.list = res.data
				});
			},
			getBuyList() {
				Wk.getBuyList({}).then(res => {
					// console.log('getBuyList.res = ', res);
					// 生成顶部卡片数据
					let buyList = res.data
					if (buyList) {
						// 托管中的订单数
						this.orderCount = buyList.length
						buyList.map((item, index) => {
							if (index == 0) {
								// 预计收益率
								this.day_rate = item.kuangj_cycle.annualized_rate
							}
							// 累计收益
							this.total_interest += parseFloat(item.Interest)
							// 托管中的资金(只计算USDT)
							if (item.kuangj_cycle.coin_name.toUpperCase() == 'USDT') {
								this.totalAmount += parseFloat(item.amount)
							}
						})
					}
				});
			},
		},
	}
</script>

<style lang="scss" scoped>
	.color_gray {
		color: #A6A6A6;
		margin: 0 0 4rpx 0;
	}

	#top_div {
		position: relative;
		display: flex;
		flex-direction: column;
		background-color: #FFE3C1;
		margin: 24rpx;
		padding: 24rpx;
		border-radius: 24rpx;
	}

	#money_total_div {
		// display: flex;
		// align-items: flex-end;
		margin: 24rpx 0 0 0;
	}

	#total_amount {
		font-size: 44rpx;
		margin: 0 12rpx 0 0;
	}

	#top_btm_3_div {
		display: flex;
		justify-content: space-between;
		margin: 48rpx 0 0 0;
	}

	.top_btm_item_div {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	#btn_weituo {
		position: fixed;
		right: 48rpx;
		font-size: 24rpx;
		color: #D3DCC2;
		background-color: #604D29;
		padding: 10rpx 20rpx;
		border-radius: 8rpx;
	}

	#wk_list_div {
		color: white;
		margin: 24rpx;
	}

	.wk_item_div {
		display: flex;
		flex-direction: column;
		background-color: #4D4D4D;
		margin: 24rpx 0 0 0;
		padding: 24rpx;
		border-radius: 24rpx;
	}

	.btn_suocang {
		background-color: #FFDDB3;
		padding: 6rpx 24rpx;
		border-radius: 8rpx;
		font-size: 24rpx;
	}

	.wk_item_btm_div {
		display: flex;
		justify-content: space-between;
		margin: 24rpx 0 0 0;
	}

	.wk_item_btm_item_div {
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>